This HTML notebook will replicate the STATA do file named vnm_mics14_dp2019 for distribution in R. The goal is to create an R script that does what the said do file does.
I will follow the same section numbering as in the do file for ease of comparision.
Before we go into the excercise, following are the packages from which we will use various functions.
library(here)
## here() starts at D:/R projects/OPHI/Vietnam Translation/Vietnam-MICS-MPI-to-R
library(tidyverse)
## -- Attaching packages --------
## v ggplot2 3.3.0 v purrr 0.3.4
## v tibble 3.0.1 v dplyr 0.8.5
## v tidyr 1.0.3 v stringr 1.4.0
## v readr 1.3.1 v forcats 0.5.0
## Warning: package 'ggplot2' was built under R version 3.6.3
## Warning: package 'tibble' was built under R version 3.6.3
## Warning: package 'purrr' was built under R version 3.6.3
## Warning: package 'dplyr' was built under R version 3.6.3
## Warning: package 'forcats' was built under R version 3.6.3
## -- Conflicts -----------------
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
library(janitor)
## Warning: package 'janitor' was built under R version 3.6.3
##
## Attaching package: 'janitor'
## The following objects are masked from 'package:stats':
##
## chisq.test, fisher.test
library(haven)
library(gt)
## Warning: package 'gt' was built under R version 3.6.3
The memory and environment clearing commands and the commands for setting working folders and paths are not needed if one is working in Project mode through RStudio and uses the {here} (read as package here). This is a library for managing paths and directories.
__ Selecting main variables from CH, WM, HH & MN recode & merging with HL recode __
It should be noted that anthropometric data was not collected for children under 5 as part of the Viet Nam MICS 2014 dataset. Previously, nutrition data was collected as part of Viet Nam MICS 2011. However, the data was not collected in this round due to time and resource constraints as well as the availability of national nutrition survey data (p.61)
Above comments are copied from the STATA do file
According to the STATA do file there is no data for this section.
The purpose of step 1.2 is to identify children of any age who died in the last 5 years prior to the survey date. As seen in the STATA file
Loading the data from bh.sav.
bh_dat <- read_sav(file = here("Viet Nam_MICS5_Datasets",
"Viet Nam MICS 2013-14 SPSS Datasets",
"bh.sav"))
bh_dat <- clean_names(bh_dat)
The above code chunk loads the bh.sav and names it bh_dat(a data object). The clean names function gets all the variable names in lower snake case. IN case if anyone is wondering what are all the possible cases, please refere to the wonderful art by Allison Horst shown below.
Various Cases (Let me know your favourite)
Now let us take a glimplse at the data and names of the variables.
names(bh_dat)
## [1] "hh1" "hh2" "ln" "bhln" "bh2" "bh3"
## [7] "bh4m" "bh4y" "bh5" "bh6" "bh7" "bh8"
## [13] "bh9u" "bh9n" "bh10" "bh4c" "bh4f" "bh9c"
## [19] "bh9f" "hh6" "hh7" "wdoi" "wdob" "ethnicity"
## [25] "welevel" "brthord" "magebrt" "birthint" "wmweight" "wscore"
## [31] "windex5" "wscoreu" "windex5u" "wscorer" "windex5r" "windex2"
head(bh_dat) %>% gt()
| hh1 | hh2 | ln | bhln | bh2 | bh3 | bh4m | bh4y | bh5 | bh6 | bh7 | bh8 | bh9u | bh9n | bh10 | bh4c | bh4f | bh9c | bh9f | hh6 | hh7 | wdoi | wdob | ethnicity | welevel | brthord | magebrt | birthint | wmweight | wscore | windex5 | wscoreu | windex5u | wscorer | windex5r | windex2 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | 2 | 2 | 1 | 1 | 1 | 4 | 2011 | 1 | 2 | 1 | 4 | NA | NA | NA | 1336 | 1 | NA | NA | 1 | 1 | 1368 | 1044 | 1 | 4 | 1 | 2 | 1 | 2.167035 | 1.640778 | 5 | 1.337577 | 5 | NA | NA | 2 |
| 1 | 2 | 2 | 2 | 1 | 1 | 5 | 2013 | 1 | 0 | 1 | 5 | NA | NA | 2 | 1361 | 1 | NA | NA | 1 | 1 | 1368 | 1044 | 1 | 4 | 2 | 2 | 2 | 2.167035 | 1.640778 | 5 | 1.337577 | 5 | NA | NA | 2 |
| 1 | 3 | 2 | 1 | 1 | 2 | 3 | 2003 | 1 | 10 | 1 | 4 | NA | NA | NA | 1239 | 1 | NA | NA | 1 | 1 | 1368 | 939 | 1 | 3 | 1 | 2 | 1 | 2.167035 | 1.427797 | 5 | 1.071892 | 5 | NA | NA | 2 |
| 1 | 3 | 2 | 2 | 1 | 1 | 6 | 2007 | 1 | 6 | 1 | 5 | NA | NA | 2 | 1290 | 1 | NA | NA | 1 | 1 | 1368 | 939 | 1 | 3 | 2 | 2 | 4 | 2.167035 | 1.427797 | 5 | 1.071892 | 5 | NA | NA | 2 |
| 1 | 4 | 2 | 1 | 1 | 2 | 11 | 2007 | 1 | 6 | 1 | 4 | NA | NA | NA | 1295 | 1 | NA | NA | 1 | 1 | 1368 | 1008 | 1 | 4 | 1 | 2 | 1 | 2.167035 | 1.613568 | 5 | 1.303632 | 5 | NA | NA | 2 |
| 1 | 6 | 2 | 1 | 1 | 1 | 3 | 1995 | 1 | 18 | 1 | 3 | NA | NA | NA | 1143 | 1 | NA | NA | 1 | 1 | 1368 | 788 | 1 | 4 | 1 | 2 | 1 | 2.167035 | 1.624926 | 5 | 1.317802 | 5 | NA | NA | 2 |